package cn.ytian.scashier;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class YConfig {

    private final Properties pps = new Properties();

    public Properties getPps() {
        return pps;
    }
    public List<String> GetList(String key) {
        List<String> L = new ArrayList<>();
        String tmp = GetValue(key);
        if (tmp==null) return null;
        L = Arrays.asList(tmp.split("\\|"));
        return L;
    }

    public String GetValue(String key) {
        return this.pps.getProperty(key);
    }


    //读取Properties的全部信息
    public void GetAllProperties() {
        Enumeration<?> en = this.pps.propertyNames(); //得到配置文件的名字
        while(en.hasMoreElements()) {
            String strKey = (String) en.nextElement();
            String strValue = this.pps.getProperty(strKey);
            System.out.println(strKey + "=" + strValue);
        }
    }

    public YConfig() {
    }

    public YConfig(String path) {
        try {
            InputStreamReader in = new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8);
             this.pps.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
